package com.dev;
import android.widget.LinearLayout;
import android.view.View.OnClickListener;
import android.view.View;
import android.widget.TextView.OnEditorActionListener;
import android.widget.TextView;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;
import android.graphics.Rect;
import android.view.View.OnFocusChangeListener;
public class PageBookmark extends LinearLayout implements OnClickListener,OnEditorActionListener,OnFocusChangeListener{
	LinearLayout topbar;
	IconView ivQuit;
	UnderlineSingleLineEditor editor;
	final String pageTitle="Bookmarks";
	MainActivity ma;
    PageBookmark(MainActivity ma){
		super(ma);
		this.ma=ma;
		setOrientation(1);
		ivQuit=new IconView(ma);
		ivQuit.setOnClickListener(this);
		ivQuit.setImageResource(R.drawable.ic_quit_thin);
		editor=new UnderlineSingleLineEditor(ma);
		editor.setPadding(9,0,9,0);
		editor.setOnEditorActionListener(this);
		editor.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
		editor.setOnFocusChangeListener(this);
		editor.setText(pageTitle);
		topbar=new LinearLayout(ma);
		topbar.setOrientation(0);
		topbar.addView(ivQuit);
		topbar.addView(editor,new LayoutParams(0,-1,1f));
		addView(topbar,ma.titlebarHeight);
	}
	@Override
	public void onClick(View view) {
		if(view==ivQuit){
			ma.gui.pageStub.removeView(this);
			ma.gui.pageStub.addView(ma.gui.webBrowserPage,0,ma.gui.pageLayoutParams);
		}
	}
	@Override
	public boolean onEditorAction(TextView textView, int p, KeyEvent keyEvent) {
		return false;
	}
	@Override
	public void onFocusChange(View view, boolean p) {
		if(view==editor){
			if(p){
				editor.setText("");
			}else{
				editor.setText(pageTitle);
			}
		}
	}
	@Override
	protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
		return true;
	}
}
